package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.Jxb;
import service.JxbService;

import java.util.List;

/**
 * 急性病表控制器
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/jxb")
public class JxbController {
    @Autowired
    private JxbService jxbService;

    // 根据ID查询疾病
    @GetMapping("/{id}")
    public Jxb getJxbById(@PathVariable Integer id) {
        Jxb jxb = jxbService.findJxbById(id);
        if (jxb != null) {
            jxbService.incrementViewCount(id);
        }
        return jxb;
    }

    // 查询所有疾病
    @GetMapping("/all")
    public List<Jxb> getAllJxb() {
        return jxbService.findAllJxb();
    }

    // 按分类查询疾病
    @GetMapping("/category/{category}")
    public List<Jxb> getJxbByCategory(@PathVariable String category) {
        return jxbService.findJxbByCategory(category);
    }

    // 按季节查询高发疾病
    @GetMapping("/season/{season}")
    public List<Jxb> getJxbBySeason(@PathVariable String season) {
        return jxbService.findJxbBySeason(season);
    }

    // 搜索疾病
    @GetMapping("/search/{keyword}")
    public List<Jxb> searchJxb(@PathVariable String keyword) {
        return jxbService.searchJxb(keyword);
    }

    // 新增疾病
    @PostMapping("/add")
    public int addJxb(@RequestBody Jxb jxb) {
        return jxbService.addJxb(jxb);
    }

    // 更新疾病
    @PutMapping("/update")
    public int updateJxb(@RequestBody Jxb jxb) {
        return jxbService.updateJxb(jxb);
    }

    // 删除疾病
    @DeleteMapping("/{id}")
    public int deleteJxb(@PathVariable Integer id) {
        return jxbService.deleteJxb(id);
    }
}